<template>
  <div class="overview">
    <div class="one">
      <div class="income">
        <img src="~assets/images/junyuanbao@3x.png">
        <span id="subscribeIncome" class="value">{{overview.subscribeIncome}}</span>
        <div class="key">粉丝订阅累计收益</div>
      </div>
      <div class="new">
        <div id="monthSubscribeCount" class="value">{{overview.monthSubscribeCount}}</div>
        <div class="key">近一月新增订阅数</div>
      </div>
      <div class="total">
        <div id="subscribePersonCount" class="value">{{overview.subscribePersonCount}}</div>
        <div class="key">累计粉丝</div>
      </div>
    </div>
    <div class="two">
      <span>当前我的订阅价：</span>
      <span class="subscribe-price" id="subscribePrice" ref="subscribePrice">{{overview.subscribePrice}}</span>
      <span class="unit"> 君元宝</span>
    </div>
  </div>
</template>

<script>
  import CommonUtil from 'common/common.util'
  import LocalDAO from 'common/localDAO'
  import RemoteDAO from 'common/remoteDAO'
  export default {
    data () {
      return {
        userCode: LocalDAO.getUserCode(),
        overview: {
          subscribeIncome: 0,
          subscribePersonCount: 0,
          monthSubscribeCount: 0,
          subscribePrice: 0
        }
      }
    },
    created () {
      this.getData();
      this.$root.eventHub.$on('getSubscribePrice',subscribePrice => {
        this.overview.subscribePrice = subscribePrice;
      })
    },
    methods: {
      getData () {
        var args = {};
        args.USER_CODE = this.userCode;
        args.COMMUNITY_STATUS = "1";
        args.COMMUNITY_TYPE = "3";
        RemoteDAO.callUC12008314(args, response => {
          if (response.error == "0") {
            var item = response.data.body[0];

            var subscribeIncome = CommonUtil.toFixed(item.SUBSCRIBE_INCOME, 0);
            var subscribePersonCount = item.SUBSCRIBE_PERSON_COUNT;
            var monthSubscribeCount = item.MONTH_SUBSCRIBE_COUNT;
            var subscribePrice = LocalDAO.getSubscribePrice();

            this.overview.subscribeIncome = subscribeIncome;
            this.overview.subscribePersonCount = subscribePersonCount;
            this.overview.monthSubscribeCount = monthSubscribeCount;
            this.overview.subscribePrice = subscribePrice;

            //更新分享页数据
            var shareFans = LocalDAO.getShareFans();
            shareFans.overview.subscribeIncome = subscribeIncome;
            shareFans.overview.subscribePersonCount = subscribePersonCount;
            shareFans.overview.monthSubscribeCount = monthSubscribeCount;
            shareFans.overview.subscribePrice = subscribePrice;
            LocalDAO.setShareFans(shareFans);
          }else{
            this.$store.dispatch('setTip',{text:response.data});
          }
        });
      }
    }
  }
</script>
